#!/bin/sh

. $(dirname $0)/system.conf


drv_name="$1"

export ENV_CC_COMPILE=$cross_compile
export ENV_KERNEL_DIR=$linux_dir

build_drv() #drv_dir
{
    local drv_dir=$1

    export ENV_CC_COMPILE=$cross_compile
    export ENV_KERNEL_DIR=$linux_dir

    cd $drv_dir && make clean && make

    return $?
}

if [ x"$drv_name" = "xall" ]; then
    for drv_dir in $(ls $project_linux_device_driver_dir/*/Makefile | xargs dirname | grep -v test_suite)
    do
        build_drv $drv_dir
    done
    exit 0
fi

if [ x"$drv_name" = "x" -o ! -d "$project_linux_device_driver_dir/$drv_name" ]; then
    echo "Usage: $(basename $0) <drv_name | all>"
    echo "    -- drv_name : compile driver $project_linux_device_driver_dir/<drv_name>"
    echo "    -- all      : compile all drivers in $project_linux_device_driver_dir"
    exit 1
fi

build_drv $project_linux_device_driver_dir/$drv_name
exit $?
